package com.huas.mapper;

import com.github.pagehelper.Page;
import com.huas.entity.Comment;
import com.huas.vo.CommentVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper {

    @Select("select id, type, title_id, pid, content,to_comment_user_id, create_by, create_time from comment where title_id = #{titleId} and type = #{type} and pid = -1")
    Page<Comment> page(Character type,Integer titleId);

    @Select("select id, type, title_id, pid, content,to_comment_user_id, create_by, create_time from comment where pid= #{id}")
    List<Comment> getChildren(Integer id);

    @Update("ALTER TABLE comment AUTO_INCREMENT = 1")
    void reset();

    @Insert("insert into comment (type, title_id, pid, content,to_comment_user_id, create_by, create_time)" +
            "values (#{type},#{titleId},#{pid},#{content},#{toCommentUserId},#{createBy},#{createTime})")
    void addComment(Comment comment);

    @Delete("delete from comment where id = #{id}")
    void delete(Integer id);

    @Select("select id, type, title_id, pid, content,to_comment_user_id, create_by, create_time from comment where id = #{id}")
    Comment select(Integer id);

    /** 评论批量删除 */
    void deleteBatch(List<Integer> ids);
    /**
     * 条件分页评论列表查询
     * */
    Page<Comment> pageAll(Character type,Integer titleId);
}
